<% layout('/layouts/default.html', {title: '第三方发送人脸结果', libs: ['validate']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header with-border">
            <div class="box-title">
                <i class="fa icon-note"></i> ${text('输入参数' )}
            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
            </div>
        </div>
        <#form:form id="inputForm" model="${fileCabinetRecord}" action="${ctx}/sd/simulateThirdParty/save" method="post" class="form-horizontal">
        <div class="box-body">
            <#form:hidden id="pictureSrc" path="userFace"/>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('警号')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="policeno" maxlength="20" class="form-control required"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('姓名')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="userName" maxlength="10" class="form-control required"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required ">*</span> ${text('状态')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:select id="respstatus"  blankOption="true" path="responseStatus" dictType="sd_file_cabinet_response_status"  class="form-control"/>
<!--                            <#form:input path="responseStatus" maxlength="4" placeholder = "1成功，2失败" class="form-control required digits"/>-->
                        </div>
                    </div>
                </div>
                <div id="uploadImg" class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-5" title="">
                            <span class="required ">*</span> ${text('录入人脸')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-7">
                            <a href="#" class="btn btn-default camera"   title="点击录入人脸" onclick="collectPicture()"><i class="fa icon-camera"></i></a>
                        </div>
                    </div>
                </div>
        </div>
        <div class="box-footer">
            <div class="row">
                <div class="col-sm-offset-2 col-sm-10">
                    <div class="col-sm-10">
                        <% if (hasPermi('sd:docRecv:edit')){ %>
                        <button type="submit" class="btn btn-sm btn-primary " id="btnSubmit"><i class="fa fa-check"></i> ${text('发 送')}</button>&nbsp;
                        <%}%>
                        <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
                    </div>
                </div>
            </div>
        </div>
    </#form:form>
</div>
</div>
<% } %>
<script>
    $("#inputForm").validate({
        submitHandler: function (form) {
            //判断有没有上传图片
            if ($('#pictureSrc').val() === '') {
                js.layer.msg('还未录入人脸!', {icon: 5});
                return false;
            }
            if ($('#respstatus').val() === '') {
                js.layer.msg('还未选择状态!', {icon: 5});
                return false;
            }
            js.ajaxSubmitForm($(form), function (data) {
                js.showMessage(data.message);
                if (data.result == Global.TRUE) {
                    // js.closeCurrentTabPage(function (contentWindow) {
                    //     contentWindow.page();
                    // });
                }
            }, "json");
        }
    });


    function collectPicture(){
        var index =js.layer.open({
            type: 2,
            area: [(js.layer.window.outerWidth-600)+'px',(js.layer.window.outerHeight-200)+'px'],
            title: '${text("录入人脸")}',
            resize: false,
            scrollbar: true,
            maxmin:true,
            content: '${ctx}/a/sd/collectPicture/form',
            success: function(layero, index){

            },
            btn: ['<i class="fa fa-check"></i> ${text("提交")}',
                '<i class="fa fa-remove"></i> ${text("关闭")}'],
            btn1: function(index, layero){
                var win = layero.iframeWindow();
                var form = {
                    inputForm: win.$('#pictureForm'),
                    btnSubmit: win.$('#btnSubmit'),
                };
                if (typeof(win.getFile()) == "undefined"){
                    js.layer.msg('请先拍照再提交!', {icon: 5});
                    return false;
                }
                var formData = new FormData;
                formData.append("file", win.getFile())
                $.ajax({
                    type: "POST",
                    url: "${ctx}/sd/simulateThirdParty/uploadFile",
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                        if(data.result===Global.TRUE){
                            js.layer.msg(data.message, {icon: 1});
                            js.layer.close(index);
                            $('#pictureSrc').val(data.data);
                            return true;
                        }else {
                            js.layer.msg(data.message, {icon: 5});
                            return false;
                        }

                    }
                })

                return false;
            }
        });
    }
</script>
